package com.example.administrator.worldapp;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends AppCompatActivity {

    EditText mEtUsername;
    EditText mEtPassword;
    Button mBtnlogin;
    Button mBtnCancel;




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initView();
        initEvent();
    }
    //设置控件的事件，编写应
    private void initView() {
        mBtnlogin=findViewById(R.id.btn_login);
        mEtUsername=findViewById(R.id.et_username);
        mEtPassword=findViewById(R.id.et_password);

    }





    private void initEvent() {
        mBtnlogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //1.获取用户输入的数据

                String username=mEtUsername.getText().toString();
                String password=mEtPassword.getText().toString();
                //2.并与内部数据比较


                if(username.equals("admin")&&password.equals("123")){
                    //2.1 如果验证通过，则跳转
                    Bundle bundle=new Bundle();
                    bundle.putString("username",username);
                    bundle.putString("password",password);
                    Intent intent=new Intent(LoginActivity.this,TeamsActivity.class);
                    intent.putExtras(bundle);
                    startActivity(intent);

                }else {
                    //2.2 否则，提示用户输入错误
                    Toast.makeText(LoginActivity.this,"用户名密码错误",Toast.LENGTH_SHORT).show();
                }




            }
        });
    }
}
